package org.lboot.s3.test;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.lboot.s3.client.S3Client;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("s3")
@AllArgsConstructor
@Api(tags = "桶方法测试")
public class S3BucketTestController {
    S3Client s3Client;


    @PostMapping("bucket/{bucketName}")
    @ApiOperation(value = "桶创建")
    public Object bucketCreate(@PathVariable("bucketName") String bucketName){
        s3Client.createBucket(bucketName);
        return "创建成功";
    }
    /**
     * 不支持: minio qiniu
     * @param bucketName 存储桶名称
     */
    @PostMapping("bucket/{bucketName}/private")
    @ApiOperation(value = "桶私有")
    public Object bucketPrivate(@PathVariable("bucketName") String bucketName){
        s3Client.setBucketPrivate(bucketName);
        return "修改成功";
    }

    /**
     * 不支持: minio qiniu
     * @param bucketName 存储桶名
     */
    @PostMapping("bucket/{bucketName}/public")
    @ApiOperation(value = "桶公开")
    public Object bucketPublic(@PathVariable("bucketName") String bucketName){
        s3Client.setBucketPublic(bucketName);
        return "修改成功";
    }

    @GetMapping("exist/{bucket}")
    @ApiOperation(value = "桶查询")
    public Object isExist(@PathVariable("bucket") String bucket){

        return s3Client.doesBucketExist(bucket);
    }

    @GetMapping("bucket/{bucketName}/acl")
    @ApiOperation(value = "桶权限")
    public Object bucketInfo(@PathVariable("bucketName") String bucketName){
        return s3Client.getBucketACL(bucketName);
    }

    @GetMapping("buckets")
    @ApiOperation(value = "桶列表")
    public Object buckets(){
        return s3Client.listBuckets();
    }

    @DeleteMapping("bucket/{bucketName}")
    @ApiOperation(value = "桶删除",notes = "")
    public Object bucketDelete(@PathVariable("bucketName") String bucketName){
        s3Client.deleteBucket(bucketName);
        return "删除成功";
    }
}
